package uml.structural.composite;

import java.util.ArrayList;

/**
 * 组合模式--容器构件<br>
 * on 2022/12/25 0:45
 */
public class Folder implements AbstractFile {
    private String folderName;

    private ArrayList<AbstractFile> children;

    public Folder(String folderName) {
        this.folderName = folderName;
        children = new ArrayList<>();
    }

    @Override
    public void addChild(AbstractFile file) {
        children.add(file);
    }

    @Override
    public void removeChild(AbstractFile file) {
        children.remove(file);
    }

    @Override
    public AbstractFile getChild(int index) {
        return children.get(index);
    }

    @Override
    public void killVirus() {
        System.out.println("~~~~开始对文件夹【" + this.folderName + "】杀毒");
        for (AbstractFile child : children) {
            child.killVirus();
        }
        System.out.println("~~~~完成对文件夹【" + this.folderName + "】杀毒\n");
    }
}
